A short description of the post.
Installing and Loading the R packages required:
Importing shapefile using st_read() of sf package. The output object is in tibble sf object class.
Reading layer `MP14_SUBZONE_WEB_PL' from data source
`C:\JunLonggggg\junlong-is415\_posts\2021-09-13-in-class-exercise-5\data\shapefile'
using driver `ESRI Shapefile'
Simple feature collection with 323 features and 15 fields
Geometry type: MULTIPOLYGON
Dimension: XY
Bounding box: xmin: 2667.538 ymin: 15748.72 xmax: 56396.44 ymax: 50256.33
Projected CRS: SVY21
Projection is in SVY21
read_rds() of readr package is used instead of readRDS() of base R is used. This is because output of read_rds() is in tibble object.
Note that there are some data issue on childcare and chas dataframe because lat and lng should be in numeric data type. The coordinate fields seems to be in decimal degress. Hence, WGS84 referencing system is assumed, we will need to convert the reference system to EPSG3414.
Note: The st_as_sf is able to tolerate the coordinates with character data type
Some parameters used below: + alpha set to 0.4 to show the number of points in one geospatial location + col is to set the color of the dots + size is to set the size of the dots
as_Spatial() of sf package.
The output is in a unique dataframe format, it has combination of list and table together
The geometric property is placed under coords
as.SpatialPoint() of as.SpatialPolygon() of maptools package
spatstat do not care about the geograhphical projection, this information will be dropped and loss, hence be careful how you treat the data.
[1] FALSE
[1] FALSE
tmap do not understand ppp format, hence we need to convert back to sf.
alternative is using plot()

Generating 99 simulations of CSR ...
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70,
71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99.
Done.